/**
 * @description router全局配置，如有必要可分文件抽离，其中asyncRoutes只有在intelligence模式下才会用到，pro版只支持remixIcon图标
 * hidden:true                        是否显示在菜单中显示路由（默认值：false）
 * alwaysShow:true                    当只有一级子路由时是否显示父路由是否显示在菜单中显示路由（默认值：false）
 * name:"Demo"                        首字母大写，一定要与vue文件的name对应起来，用于noKeepAlive缓存控制（该项特别重要）
 * menuHidden:true                    常规/横向/纵向模式中，隐藏根布局，仅适用于第一层路由
 * meta:{
    title:"title"                     菜单、面包屑、多标签页显示的名称
    roles:["admin","..."]             当config/settings.js中rolesControl配置开启时，用于控制角色
    roles: {
      role: ["admin"],                role: ["admin"]
      ability: ["READ","WRITE"],      ability: ["READ","WRITE"],
      mode: "allOf"                   allOf: 数组内所有角色都拥有，返回True
                                      oneOf: 数组内拥有任一角色，返回True(等价第1种数据)
                                      except: 不拥有数组内任一角色，返回True(取反)
    }
    remixIcon:""                      remix图标
    isCustomSvgIcon:false,            是否是自定义svg图标（默认值：false，如果设置true，那么需要把你的svg拷贝到icon/remixIcon下，然后remixIcon字段配置上你的图标名）
    noKeepAlive:true                  当前路由是否不缓存（默认值：false）
    affix:true                        当前路由是否固定多标签页
    badge:"New"                       badge小标签（只支持子级）
    tagHidden:true                    当前路由是否不显示多标签页
   }
 */
import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from '@/vab/layouts'
import { publicPath, routerMode } from '@/config'

Vue.use(VueRouter)
export const constantRoutes = [
  {
    path: '/403',
    name: '403',
    component: () => import('@/views/403'),
    hidden: true,
  },
  {
    path: '/404',
    name: '404',
    component: () => import('@/views/404'),
    hidden: true,
  },
]

export let asyncRoutes = [
  {
    path: '/',
    component: Layout,
    hidden: true,
    redirect: '/verification',
    meta: {
      title: '验证身份',
      remixIcon: 'home-2-line',
    },
    children: [
      {
        path: 'verification',
        name: 'Verification',
        component: () => import('@/views/verification'),
        meta: {
          title: '验证身份',
          remixIcon: 'home-2-line',
        },
      },
    ],
  },
  {
    path: '/separate',
    component: Layout,
    hidden: false,
    // redirect: '/separate/counselor',
    meta: {
      title: '分销',
      remixIcon: 'account-circle-fill',
    },
    children: [
      {
        path: 'counselor',
        name: 'Counselor',
        hidden: true,
        component: () => import('@/views/counselor'),
        meta: {
          title: '招生顾问管理',
          remixIcon: 'account-circle-fill',
        },
      },
      {
        path: 'distribution',
        name: 'Distribution',
        hidden: true,
        component: () => import('@/views/distribution'),
        meta: {
          title: '分销员管理',
          remixIcon: 'account-pin-box-fill',
        },
      },
      {
        path: 'audit',
        name: 'Audit',
        hidden: true,
        component: () => import('@/views/audit'),
        meta: {
          title: '提现审核',
          remixIcon: 'book-read-fill',
          affix: true,
        },
      },
      {
        path: 'order',
        name: 'Order',
        hidden: true,
        component: () => import('@/views/order'),
        meta: {
          title: '订单管理',
          remixIcon: 'exchange-line',
          affix: true,
        },
      },
      {
        path: 'operate',
        name: 'Operate',
        hidden: true,
        component: () => import('@/views/opertation'),
        meta: {
          title: '操作记录',
          remixIcon: 'stackshare-line',
          affix: true,
        },
      },
      {
        path: 'editInfo',
        name: 'EditInfo',
        hidden: true,
        component: () => import('@/views/editInfo'),
        meta: {
          title: '验证招生顾问',
          remixIcon: 'checkbox-line',
          affix: true,
        },
      },
      {
        path: 'distri_operation',
        name: 'Distri_operation',
        hidden: true,
        component: () => import('@/views/distri_operation'),
        meta: {
          title: '分销设置',
          remixIcon: 'folder-settings-fill',
          affix: true,
        },
      },
      {
        path: 'intergral',
        name: 'Intergral',
        hidden: true,
        component: () => import('@/views/integral'),
        meta: {
          title: '积分明细',
          remixIcon: 'money-cny-circle-line',
          affix: true,
        },
      },
    ],
  },
  // {
  //   path: '/counselor',
  //   component: Layout,
  //   hidden: true,
  //   redirect: '/counselor',
  //   meta: {
  //     title: '招生顾问管理',
  //     remixIcon: 'account-circle-fill',
  //   },
  //   children: [
  //     {
  //       path: 'counselor',
  //       name: 'Counselor',
  //       component: () => import('@/views/counselor'),
  //       meta: {
  //         title: '招生顾问管理',
  //         remixIcon: 'account-circle-fill',
  //       },
  //     },
  //   ],
  // },
  // {
  //   path: '/distribution',
  //   component: Layout,
  //   redirect: '/distribution',
  //   hidden: true,
  //   meta: {
  //     title: '分销员管理',
  //     remixIcon: 'account-pin-box-fill',
  //   },
  //   children: [
  //     {
  //       path: 'distribution',
  //       name: 'Distribution',
  //       component: () => import('@/views/distribution'),
  //       meta: {
  //         title: '分销员管理',
  //         remixIcon: 'account-pin-box-fill',
  //       },
  //     },
  //   ],
  // },
  {
    path: '/detail',
    component: Layout,
    hidden: true,
    meta: {
      title: '详情',
      remixIcon: 'stackshare-line',
    },
    children: [
      {
        path: ':id',
        component: () => import('@/views/detail'),
        meta: {
          title: '详情',
          remixIcon: 'stackshare-line',
          affix: true,
        },
      },
    ],
  },
  // {
  //   path: '/audit',
  //   component: Layout,
  //   hidden: true,
  //   meta: {
  //     title: '提现审核',
  //     remixIcon: 'book-read-fill',
  //   },
  //   children: [
  //     {
  //       path: 'audit',
  //       name: 'Audit',
  //       component: () => import('@/views/audit'),
  //       meta: {
  //         title: '提现审核',
  //         remixIcon: 'book-read-fill',
  //         affix: true,
  //       },
  //     },
  //   ],
  // },
  // {
  //   path: '/order',
  //   component: Layout,
  //   hidden: true,
  //   meta: {
  //     title: '订单管理',
  //     remixIcon: 'exchange-line',
  //   },
  //   children: [
  //     {
  //       path: 'order',
  //       name: 'Order',
  //       component: () => import('@/views/order'),
  //       meta: {
  //         title: '订单管理',
  //         remixIcon: 'exchange-line',
  //         affix: true,
  //       },
  //     },
  //   ],
  // },
  // {
  //   path: '/operate',
  //   component: Layout,
  //   hidden: true,
  //   meta: {
  //     title: '操作记录',
  //     remixIcon: 'stackshare-line',
  //   },
  //   children: [
  //     {
  //       path: 'operate',
  //       name: 'Operate',
  //       component: () => import('@/views/opertation'),
  //       meta: {
  //         title: '操作记录',
  //         remixIcon: 'stackshare-line',
  //         affix: true,
  //       },
  //     },
  //   ],
  // },
  // {
  //   path: '/edit',
  //   component: Layout,
  //   hidden: true,
  //   meta: {
  //     title: '验证招生顾问',
  //     remixIcon: 'checkbox-line',
  //   },
  //   children: [
  //     {
  //       path: 'editInfo',
  //       name: 'EditInfo',
  //       component: () => import('@/views/editInfo'),
  //       meta: {
  //         title: '验证招生顾问',
  //         remixIcon: 'checkbox-line',
  //         affix: true,
  //       },
  //     },
  //   ],
  // },
  // {
  //   path: '/distri_operation',
  //   component: Layout,
  //   hidden: true,
  //   meta: {
  //     title: '分销设置',
  //     remixIcon: 'folder-settings-fill',
  //   },
  //   children: [
  //     {
  //       path: 'distri_operation',
  //       name: 'Distri_operation',
  //       component: () => import('@/views/distri_operation'),
  //       meta: {
  //         title: '分销设置',
  //         remixIcon: 'folder-settings-fill',
  //         affix: true,
  //       },
  //     },
  //   ],
  // },
  // {
  //   path: '/intergral',
  //   component: Layout,
  //   hidden: true,
  //   meta: {
  //     title: '积分明细',
  //     remixIcon: 'money-cny-circle-line',
  //   },
  //   children: [
  //     {
  //       path: 'intergral',
  //       name: 'Intergral',
  //       component: () => import('@/views/integral'),
  //       meta: {
  //         title: '积分明细',
  //         remixIcon: 'money-cny-circle-line',
  //         affix: true,
  //       },
  //     },
  //   ],
  // },
  // 高职高考
  {
    path: '/college',
    component: Layout,
    hidden: false,
    meta: {
      title: '高职高考',
      remixIcon: 'book-read-fill',
    },
    children: [
      {
        path: 'user',
        name: 'User',
        component: () => import('@/views/gaozhigaokao/user'),
        meta: {
          title: '用户列表',
          remixIcon: 'user-line',
          affix: true,
        },
      },
      {
        path: 'academy',
        name: 'Academy',
        component: () => import('@/views/gaozhigaokao/academy'),
        meta: {
          title: '院校列表',
          remixIcon: 'user-line',
          affix: true,
        },
      },
      {
        path: 'specialty',
        name: 'Specialty',
        component: () => import('@/views/gaozhigaokao/specialty'),
        meta: {
          title: '专业列表',
          remixIcon: 'user-line',
          affix: true,
        },
      },
      {
        path: 'certificate',
        name: 'Certificate',
        component: () => import('@/views/gaozhigaokao/certificate'),
        meta: {
          title: '证书列表',
          remixIcon: 'user-line',
          affix: true,
        },
      },
      {
        path: 'class',
        name: 'Class',
        component: () => import('@/views/gaozhigaokao/class'),
        meta: {
          title: '教材课程',
          remixIcon: 'user-line',
          affix: true,
        },
      },
      {
        path: 'region',
        name: 'Region',
        component: () => import('@/views/gaozhigaokao/region'),
        meta: {
          title: '地区微群',
          remixIcon: 'user-line',
          affix: true,
        },
      },
      {
        path: 'comment',
        name: 'Comment',
        component: () => import('@/views/gaozhigaokao/comment'),
        meta: {
          title: '意见反馈',
          remixIcon: 'user-line',
          affix: true,
        },
      },
      // {
      //   path: 'news',
      //   name: 'News',
      //   component: () => import('@/views/gaozhigaokao/news'),
      //   meta: {
      //     title: '新闻头条',
      //     remixIcon: 'user-line',
      //     affix: true,
      //   },
      // },
    ],
  },

  {
    path: '*',
    redirect: '/404',
    hidden: true,
  },
]

const router = createRouter()

export function resetRouter(routes = constantRoutes) {
  router.matcher = createRouter(routes).matcher
}

function createRouter(routes = constantRoutes) {
  return new VueRouter({
    base: publicPath,
    mode: routerMode,
    scrollBehavior: () => ({
      y: 0,
    }),
    routes: routes,
  })
}

const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location, onResolve, onReject) {
  if (onResolve || onReject)
    return originalPush.call(this, location, onResolve, onReject)
  return originalPush.call(this, location).catch((err) => err)
}

export default router
